﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CSharp.Libs.Koc;
using System.Collections;

namespace CSharp.Libs.WPF.UserControls
{
    /// <summary>
    /// Interaktionslogik für AllianceList.xaml
    /// </summary>
    public partial class AllianceList : UserControl
    {
        #region declarations
        private Kernel _KRNL = null;
        private AllianceListViewModel _AMVVM = null;

        public delegate void AllianceClickedEventHandler(object sender, int AllianceId);
        public event AllianceClickedEventHandler AllianceClicked;
        private void ThrowAllianceClickedEvent(
            int AllianceId)
        {
            if (AllianceClicked != null)
            {
                AllianceClicked(this, AllianceId);
            }
        }
        #endregion



        #region constructor destructor
        public AllianceList()
        {
            InitializeComponent();
        }
        #endregion



        #region event handling
        /// <summary>mnuListAllianceMembers_Click</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>created  09.01.2012</history>
        private void mnuListAllianceMembers_Click(object sender, RoutedEventArgs e)
        {
            if (lvAllyList.SelectedItems.Count == 1)
            {
                KocAllianceListItem KALI = lvAllyList.SelectedItem as KocAllianceListItem;
                if (KALI != null)
                {
                    int intAllianceId = -1;
                    if (int.TryParse(KALI.AllianceId, out intAllianceId))
                    {
                        ThrowAllianceClickedEvent(intAllianceId);
                    }
                }
            }
            else if (lvAllyList.SelectedItems.Count > 1)
            {
                MessageBox.Show("Please do not select more than one alliance to view.");
            }
        }
        #endregion



        #region private functions
        private void _Initialize(
            Kernel KRNL)
        {
            _KRNL = KRNL;
            _AMVVM = new AllianceListViewModel(_KRNL);
            DataContext = _AMVVM;
        }
        #endregion



        #region interface
        #region properties
        public AllianceListViewModel AMVVM
        {
            get
            {
                return _AMVVM;
            }
        }
        #endregion

        #region methods
        public void Initialize(
            Kernel KRNL)
        {
            _Initialize(KRNL);
        }
        #endregion
        #endregion
    }
}
